package Settings;

import java.awt.Color;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Observable;

/**
 * This class contains the setting for sequence specific visualization
 * @author Stefan Lorenz<br>
 * <br>26.11.2012
 */
@SuppressWarnings("serial")
public class SequenceSettings extends Observable implements Serializable{

	
	/**
	 * is the sequence shown or invisible
	 */
	private boolean isShown;

	/**
	 * The size of the chars of the sequence
	 */
	private int size;
	/**
	 * The color of the nucleotide background
	 */
	private Color[] nucleotideBackgroundColor;
	/**
	 * The color of the nucleotide foreground
	 */
	private Color nucleotideForegroundColor;
	/**
	 * The y position of the + sequence
	 */
	private int positionPlusStrand;
	/**
	 * The y position of the - sequence
	 */
	private int positionMinusStrand;
	
	/**
	 * Constructor of the standard sequence settings
	 */
	public SequenceSettings() {
		this.nucleotideForegroundColor = Color.BLACK;
		this.isShown = true;
		this.size = 10;
		this.nucleotideBackgroundColor = new Color[5];
		this.nucleotideBackgroundColor[0] = Color.RED;
		this.nucleotideBackgroundColor[1] = Color.YELLOW;
		this.nucleotideBackgroundColor[2] = Color.CYAN;
		this.nucleotideBackgroundColor[3] = Color.GREEN;
		this.nucleotideBackgroundColor[4] = Color.WHITE;
		
		this.positionMinusStrand = 150;
		this.positionPlusStrand = 130;
	}

	/**
	 * Is the sequence shown??
	 * @return boolean if sequence is shown or not
	 */
	public boolean isShown() {
		return isShown;
	}

	/**
	 * Sets the sequence visible or invisible
	 * @param isShown
	 */
	public void setShown(boolean isShown) {
		this.isShown = isShown;
		setChanged();
	}

	/**
	 * Sets the size of the sequence letters
	 * @return size of the sequence letters
	 */
	public int getSize() {
		return size;
	}

	/**
	 * Sets the size of the sequence letters
	 * @param size size of the sequence letters
	 */
	public void setSize(int size) {
		this.size = size;
		setChanged();
	}

	/**
	 * Sets the background color 
	 * @param baseColor the background color of a nucleotide<br>
	 * 0: A<br>
	 * 1: T<br>
	 * 2: G<br>
	 * 3: C<br>
	 * 4: else
	 */
	public void setNucleotideBackgroundColor(Color baseColor, int index) {
		this.nucleotideBackgroundColor[index] = baseColor;
		setChanged();
	}

	/**
	 * Returns the background color of a nucleotide
	 * @return the baseColor background color of a nucleotide
	 * 0: A<br>
	 * 1: T<br>
	 * 2: G<br>
	 * 3: C<br>
	 * 4: else
	 */
	public Color getNucleotideBackgroundColor(int index) {
		return nucleotideBackgroundColor[index];
	}

	/**
	 * Sets the y position of the plus strand
	 * @param positionPlusStrand the position of the plus strand
	 */
	public void setPositionPlusStrand(int positionPlusStrand) {
		this.positionPlusStrand = positionPlusStrand;
		setChanged();
	}

	/**
	 * Returns the y position of the plus strand
	 * @return the position of the plus strand
	 */
	public int getPositionPlusStrand() {
		return positionPlusStrand;
	}

	/**
	 * Sets the y position of the minus strand
	 * @param positionMinusStrand the position of the minus strand
	 */
	public void setPositionMinusStrand(int positionMinusStrand) {
		this.positionMinusStrand = positionMinusStrand;
		setChanged();
	}

	/**
	 * Returns the y position of the minus strand
	 * @return the position of the minus strand
	 */
	public int getPositionMinusStrand() {
		return positionMinusStrand;
	}

	/**
	 * Sets the foreground color of a nucleotide
	 * @param baseTextColor foreground color
	 */
	public void setNucleotideForegroundColor(Color baseTextColor) {
		this.nucleotideForegroundColor = baseTextColor;
		setChanged();
	}

	/**
	 * Returns the foreground color of a nucleotide
	 * @return the foreground color
	 */
	public Color getNucleotideForegroundColor() {
		return nucleotideForegroundColor;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "SequenceSettings [isShown=" + isShown + ", size=" + size + ", baseColor=" + Arrays.toString(nucleotideBackgroundColor) + ", baseTextColor=" + nucleotideForegroundColor + ", positionPlusStrand="
				+ positionPlusStrand + ", positionMinusStrand=" + positionMinusStrand + "]";
	}
	
	/* (non-Javadoc)
	 * @see java.util.Observable#setChanged()
	 */
	@Override
	protected synchronized void setChanged() {
		super.setChanged();
		notifyObservers();
	}
	
}
